<template>
  <div class="step-two">
    <Header :active-step="currentStep" />
    <h3>完善信息</h3>
    <el-table :data="tableData" border style="width: 100%; margin-top: 20px;">
      <el-table-column label="序号" type="index" width="50" align="center" />
      <el-table-column label="* 品牌名称" prop="brandName" width="180">
        <template slot-scope="scope">
          <el-select v-model="scope.row.brandName" placeholder="请输入关键词">
            <el-option label="品牌A" value="品牌A" />
            <el-option label="品牌B" value="品牌B" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="* 类目" prop="category" width="160">
        <template slot-scope="scope">
          <el-select v-model="scope.row.category" placeholder="请选择" multiple>
            <el-option label="氟基材料" value="氟基材料" />
            <el-option label="供应链服务" value="供应链服务" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="* 覆盖区域" width="110" align="center">
        <template slot-scope="scope">
          <el-button type="text">编辑</el-button>
        </template>
      </el-table-column>
      <el-table-column label="* 是否代理品牌" prop="isAgent" width="140">
        <template slot-scope="scope">
          <el-select v-model="scope.row.isAgent" placeholder="请选择">
            <el-option label="是" value="是" />
            <el-option label="否" value="否" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="* 是否原厂品牌" prop="isOriginal" width="160">
        <template slot-scope="scope">
          <el-select v-model="scope.row.isOriginal" placeholder="请选择">
            <el-option label="是-有商标注册证" value="是-有商标注册证" />
            <el-option label="是-无商标注册证" value="是-无商标注册证" />
            <el-option label="否" value="否" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="* 是否授权平台" prop="isAuthorized" width="152">
        <template slot-scope="scope">
          <el-select v-model="scope.row.isAuthorized" placeholder="请选择">
            <el-option label="是" value="是" />
            <el-option label="否" value="否" />
          </el-select>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="90" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="deleteRow(scope.$index)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-button type="text" @click="addRow">+增加一行</el-button>
    <div class="step-buttons">
      <el-button @click="$emit('prev')">上一步</el-button>
      <el-button type="danger" @click="submit">下一步</el-button>
    </div>
  </div>
</template>

<script>
import { submitBrandInfo } from '@/api/auth/auth';
import Header from "@/views/auth/Header.vue";

export default {
  name: 'StepTwo',
  components: {
    Header // 正确注册组件
  },
  data() {
    return {
      tableData: [
        { brandName: '', category: [], isAgent: '', isOriginal: '', isAuthorized: '' }
      ]
    };
  },
  methods: {
    addRow() {
      this.tableData.push({ brandName: '', category: [], isAgent: '', isOriginal: '', isAuthorized: '' });
    },
    deleteRow(index) {
      this.tableData.splice(index, 1);
    },
    async submit() {
      if (this.tableData.every(row => row.brandName && row.category.length && row.isAgent && row.isOriginal && row.isAuthorized)) {
        try {
          await submitBrandInfo(this.tableData);
          this.$message.success('信息完善完成');
          this.$emit('next', 2);
        } catch (error) {
          this.$message.error('提交失败');
        }
      } else {
        this.$message.error('请完善品牌信息');
      }
    }
  }
};
</script>

<style scoped>
.step-two {
  padding: 20px;
}
.step-buttons {
  margin-top: 20px;
}
.step-buttons .el-button {
  margin: 0 10px;
}
</style>
